﻿using Application.ISale_hService;
using AutoMapper;
using Domain.Entity.ord;
using Domain.IRepository;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Application.Sale_dService
{
    public class Sale_dService : ISale_dService
    {
        private readonly ISale_dRepository sale_DRepository;
        private readonly IMapper mapper;

        public Sale_dService(ISale_dRepository sale_DRepository,IMapper mapper)
        {
            this.sale_DRepository = sale_DRepository;
            this.mapper = mapper;
        }

        //添加销售明细单
        public async Task<int> AddSale_d(AddSale_dDto addSale_DDto)
        {
            //转换
            Sale_d sale_D = mapper.Map<Sale_d>(addSale_DDto);
            return await sale_DRepository.AddSale_d(sale_D);
        }

        //删除销售明细单
        public async Task<int> DeleteSale_d(int saleid)
        {
            return await sale_DRepository.DeleteSale_d(saleid);
        }


        //根据销售单与货品获取到主键id
        public async Task<int> Getid(int saleid, int procid)
        {
            return await sale_DRepository.Getid(saleid, procid);
        }


        //根据销售单id查询明细
        public async Task<List<Sale_d>> GetSale_ds(int saleid)
        {
            return await sale_DRepository.GetSale_ds(saleid);
        }


        //更新出库数量
        public async Task<int> UpdateNum(int saledid, int oknum, int nonum)
        {
            return await sale_DRepository.UpdateNum(saledid, oknum, nonum);
        }


        //更新退货数量
        public async Task<int> UpdateRNum(int saledid, int returnnum)
        {
            return await sale_DRepository.UpdateRNum(saledid, returnnum);
        }

        public async Task<int> UpdateRNum(int saledid, int returnnum, int newnum)
        {
            return await sale_DRepository.UpdateRNum(saledid,returnnum,newnum);
        }
    }
}
